package com.irdstudio.efp.console.service.impl;

import java.util.List;
import java.util.ArrayList;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.console.service.dao.DataPlatformServiceCfgDao;
import com.irdstudio.efp.console.service.domain.DataPlatformServiceCfg;
import com.irdstudio.efp.console.service.facade.DataPlatformServiceCfgService;
import com.irdstudio.efp.console.service.vo.DataPlatformServiceCfgVO;

/**
 * <p>
 * 请求数据平台服务配置的Service实现类
 * </p>
 * @author szbd
 * @createDate 2018-11-15 18:03:22
 */
@Service("dataPlatformServiceCfgService")
public class DataPlatformServiceCfgServiceImpl implements DataPlatformServiceCfgService, FrameworkService {
    
    private static Logger logger = LoggerFactory.getLogger(DataPlatformServiceCfgServiceImpl.class);
    
    @Autowired
    private DataPlatformServiceCfgDao dataPlatformServiceCfgDao;
    
    @Override
    public List<DataPlatformServiceCfgVO> queryAllOwner(DataPlatformServiceCfgVO inDataPlatformServiceCfgVo) {
        logger.info("查询本人所属的请求数据平台服务配置记录的请求参数为：" + JSONObject.toJSONString(inDataPlatformServiceCfgVo));
        if(Objects.isNull(inDataPlatformServiceCfgVo)){
            return null;
        }
        try {
            List<DataPlatformServiceCfg> dataList = dataPlatformServiceCfgDao.queryAllOwnerByPage(inDataPlatformServiceCfgVo);
            if (Objects.nonNull(dataList)) {
                List<DataPlatformServiceCfgVO> resultList = new ArrayList<DataPlatformServiceCfgVO>();
                resultList = (List<DataPlatformServiceCfgVO>) beansCopy(dataList, DataPlatformServiceCfgVO.class);
                return resultList;
            } else {
                logger.info("查询本人所属的请求数据平台服务配置记录为空！");
            }
        } catch (Exception e) {
            logger.error("查询本人所属的请求数据平台服务配置记录发生异常！", e);
        }
        return null;
    }
    
    @Override
    public List<DataPlatformServiceCfgVO> queryAllCurrOrg(DataPlatformServiceCfgVO inDataPlatformServiceCfgVo) {
        logger.info("查询本机构的请求数据平台服务配置记录的请求参数为：" + JSONObject.toJSONString(inDataPlatformServiceCfgVo));
        if(Objects.isNull(inDataPlatformServiceCfgVo)){
            return null;
        }
        try {
            List<DataPlatformServiceCfg> dataList = dataPlatformServiceCfgDao.queryAllCurrOrgByPage(inDataPlatformServiceCfgVo);
            if (Objects.nonNull(dataList)) {
                List<DataPlatformServiceCfgVO> resultList = new ArrayList<DataPlatformServiceCfgVO>();
                resultList = (List<DataPlatformServiceCfgVO>) beansCopy(dataList, DataPlatformServiceCfgVO.class);
                return resultList;
            } else {
                logger.info("查询本机构的请求数据平台服务配置记录为空！");
            }
        } catch (Exception e) {
            logger.error("查询本机构的请求数据平台服务配置记录发生异常！", e);
        }
        return null;
    }
    
    @Override
    public List<DataPlatformServiceCfgVO> queryAllCurrDownOrg(DataPlatformServiceCfgVO inDataPlatformServiceCfgVo) {
        logger.info("查询本机构及下属机构的请求数据平台服务配置记录的请求参数为：" + JSONObject.toJSONString(inDataPlatformServiceCfgVo));
        if(Objects.isNull(inDataPlatformServiceCfgVo)){
            return null;
        }
        try {
            List<DataPlatformServiceCfg> dataList = dataPlatformServiceCfgDao.queryAllCurrDownOrgByPage(inDataPlatformServiceCfgVo);
            if (Objects.nonNull(dataList)) {
                List<DataPlatformServiceCfgVO> resultList = new ArrayList<DataPlatformServiceCfgVO>();
                resultList = (List<DataPlatformServiceCfgVO>) beansCopy(dataList, DataPlatformServiceCfgVO.class);
                return resultList;
            } else {
                logger.info("查询本机构及下属机构的请求数据平台服务配置记录为空！");
            }
        } catch (Exception e) {
            logger.error("查询本机构及下属机构的请求数据平台服务配置记录发生异常！", e);
        }
        return null;
    }
    
    @Override
    public int insertDataPlatformServiceCfg(DataPlatformServiceCfgVO inDataPlatformServiceCfgVo) {
        logger.info("新增请求数据平台服务配置数据的参数为：" + JSONObject.toJSONString(inDataPlatformServiceCfgVo));
        if(Objects.isNull(inDataPlatformServiceCfgVo)){
            return 0;
        }
        int count = 0;
        try {
            DataPlatformServiceCfg dataPlatformServiceCfg = new DataPlatformServiceCfg();
            beanCopy(inDataPlatformServiceCfgVo, dataPlatformServiceCfg);
            count = dataPlatformServiceCfgDao.insertDataPlatformServiceCfg(dataPlatformServiceCfg);
        } catch (Exception e) {
            logger.error("新增请求数据平台服务配置数据发生异常！", e);
            count = -1;
        }
        logger.info("当前新增请求数据平台服务配置数据条数为：" + count);
        return count;
    }
    
    @Override
    public int deleteDataPlatformServiceCfgByPk(DataPlatformServiceCfgVO inDataPlatformServiceCfgVo) {
        logger.info("删除请求数据平台服务配置数据的参数为：" + JSONObject.toJSONString(inDataPlatformServiceCfgVo));
        if(Objects.isNull(inDataPlatformServiceCfgVo)){
            return 0;
        }
        int count = 0;
        try {
            DataPlatformServiceCfg dataPlatformServiceCfg = new DataPlatformServiceCfg();
            beanCopy(inDataPlatformServiceCfgVo, dataPlatformServiceCfg);
            count = dataPlatformServiceCfgDao.deleteDataPlatformServiceCfgByPk(dataPlatformServiceCfg);
        } catch (Exception e) {
            logger.error("删除请求数据平台服务配置数据发生异常！", e);
            count = -1;
        }
        logger.info("删除的请求数据平台服务配置数据条数为：" + count);
        return count;
    }
    
    @Override
    public int updateDataPlatformServiceCfgByPk(DataPlatformServiceCfgVO inDataPlatformServiceCfgVo) {
        logger.info("修改请求数据平台服务配置数据的参数为：" + JSONObject.toJSONString(inDataPlatformServiceCfgVo));
        if(Objects.isNull(inDataPlatformServiceCfgVo)){
            return 0;
        }
        int count = 0;
        try {
            DataPlatformServiceCfg dataPlatformServiceCfg = new DataPlatformServiceCfg();
            beanCopy(inDataPlatformServiceCfgVo, dataPlatformServiceCfg);
            count = dataPlatformServiceCfgDao.updateDataPlatformServiceCfgByPk(dataPlatformServiceCfg);
        } catch (Exception e) {
            logger.error("修改数据发生异常！", e);
            count = -1;
        }
        logger.info("修改的请求数据平台服务配置数据条数为" + count);
        return count;
    }
    
    @Override
    public DataPlatformServiceCfgVO queryDataPlatformServiceCfgByPk(DataPlatformServiceCfgVO inDataPlatformServiceCfgVo) {
        logger.info("根据主键查询请求数据平台服务配置的请求参数为：" + JSONObject.toJSONString(inDataPlatformServiceCfgVo));
        if(Objects.isNull(inDataPlatformServiceCfgVo)){
            return null;
        }
        try {
            DataPlatformServiceCfg dataPlatformServiceCfg = new DataPlatformServiceCfg();
            beanCopy(inDataPlatformServiceCfgVo, dataPlatformServiceCfg);
            dataPlatformServiceCfg = dataPlatformServiceCfgDao.queryDataPlatformServiceCfgByPk(dataPlatformServiceCfg);
            if (Objects.nonNull(dataPlatformServiceCfg)) {
                DataPlatformServiceCfgVO outDataPlatformServiceCfgVo = beanCopy(dataPlatformServiceCfg, new DataPlatformServiceCfgVO());
                return outDataPlatformServiceCfgVo;
            } else {
                logger.info("根据主键查询请求数据平台服务配置的记录为空！");
            }
        } catch (Exception e) {
            logger.error("根据主键查询请求数据平台服务配置记录发生异常！", e);
        }
        return null;
    }
    
    @Override
    public DataPlatformServiceCfgVO querySingleDataPlatformServiceCfgByCondition(DataPlatformServiceCfgVO inDataPlatformServiceCfgVo) {
        logger.info("根据条件查询单笔请求数据平台服务配置的请求参数为：" + JSONObject.toJSONString(inDataPlatformServiceCfgVo));
        if(Objects.isNull(inDataPlatformServiceCfgVo)){
            return null;
        }
        try {
            DataPlatformServiceCfg dataPlatformServiceCfg = new DataPlatformServiceCfg();
            beanCopy(inDataPlatformServiceCfgVo, dataPlatformServiceCfg);
            dataPlatformServiceCfg = dataPlatformServiceCfgDao.querySingleDataPlatformServiceCfgByCondition(dataPlatformServiceCfg);
            if (Objects.nonNull(dataPlatformServiceCfg)) {
                DataPlatformServiceCfgVO outDataPlatformServiceCfgVo = beanCopy(dataPlatformServiceCfg, new DataPlatformServiceCfgVO());
                return outDataPlatformServiceCfgVo;
            } else {
                logger.info("根据条件查询单笔请求数据平台服务配置的记录为空！");
            }
        } catch (Exception e) {
            logger.error("根据条件查询单笔请求数据平台服务配置记录发生异常！", e);
        }
        return null;
    }
    
    @Override
    public List<DataPlatformServiceCfgVO> queryDataPlatformServiceCfgByCondition(DataPlatformServiceCfgVO inDataPlatformServiceCfgVo) {
        logger.info("条件查询请求数据平台服务配置的请求参数为：" + JSONObject.toJSONString(inDataPlatformServiceCfgVo));
        if(Objects.isNull(inDataPlatformServiceCfgVo)){
            return null;
        }
        try {
            List<DataPlatformServiceCfg> dataList = dataPlatformServiceCfgDao.queryDataPlatformServiceCfgByCondition(inDataPlatformServiceCfgVo);
            if (Objects.nonNull(dataList)) {
                List<DataPlatformServiceCfgVO> resultList = new ArrayList<DataPlatformServiceCfgVO>();
                resultList = (List<DataPlatformServiceCfgVO>) beansCopy(dataList, DataPlatformServiceCfgVO.class);
                return resultList;
            } else {
                logger.info("条件查询请求数据平台服务配置的数据为空！");
            }
        } catch (Exception e) {
            logger.error("条件查询请求数据平台服务配置发生异常！", e);
        }
        return null;
    }
    
    @Override
    public List<DataPlatformServiceCfgVO> queryDataPlatformServiceCfgByConditionByPage(DataPlatformServiceCfgVO inDataPlatformServiceCfgVo) {
        logger.info("条件分页查询请求数据平台服务配置的请求参数为：" + JSONObject.toJSONString(inDataPlatformServiceCfgVo));
        if(Objects.isNull(inDataPlatformServiceCfgVo)){
            return null;
        }
        try {
            List<DataPlatformServiceCfg> dataList = dataPlatformServiceCfgDao.queryDataPlatformServiceCfgByConditionByPage(inDataPlatformServiceCfgVo);
            if (Objects.nonNull(dataList)) {
                List<DataPlatformServiceCfgVO> resultList = new ArrayList<DataPlatformServiceCfgVO>();
                resultList = (List<DataPlatformServiceCfgVO>) beansCopy(dataList, DataPlatformServiceCfgVO.class);
                return resultList;
            } else {
                logger.info("条件分页查询请求数据平台服务配置的数据为空！");
            }
        } catch (Exception e) {
            logger.error("条件分页查询请求数据平台服务配置发生异常！", e);
        }
        return null;
    }
}